package com.axzhengxin.platform.business.service.impl;

import java.util.List;

import com.axzhengxin.platform.business.domain.BizInsuranceInfo;
import com.axzhengxin.platform.business.domain.BizRenewLoanInfo;
import com.axzhengxin.platform.business.mapper.BizRenewLoanInfoMapper;
import com.axzhengxin.platform.business.service.IBizRenewLoanInfoService;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 续贷信息Service业务层处理
 * 
 * @author axzhengxin
 * @date 2021-04-01
 */
@Service
public class BizRenewLoanInfoServiceImpl implements IBizRenewLoanInfoService
{
    @Autowired
    private BizRenewLoanInfoMapper bizRenewLoanInfoMapper;

    /**
     * 查询续贷信息
     * 
     * @param renewLoanId 续贷信息ID
     * @return 续贷信息
     */
    @Override
    public BizRenewLoanInfo selectBizRenewLoanInfoById(String renewLoanId)
    {
        return bizRenewLoanInfoMapper.selectBizRenewLoanInfoById(renewLoanId);
    }

    /**
     * 查询续贷信息列表
     * 
     * @param bizRenewLoanInfo 续贷信息
     * @return 续贷信息
     */
    @Override
    @DataScope(deptAlias = "sd")
    public List<BizRenewLoanInfo> selectBizRenewLoanInfoList(BizRenewLoanInfo bizRenewLoanInfo)
    {
        List<BizRenewLoanInfo> bizRenewLoanInfos = bizRenewLoanInfoMapper.selectBizRenewLoanInfoList(bizRenewLoanInfo);
        bizRenewLoanInfos=buildBizRenewLoanInfos(bizRenewLoanInfos);
        return bizRenewLoanInfos;
    }

    /**
     * 新增续贷信息
     * 
     * @param bizRenewLoanInfo 续贷信息
     * @return 结果
     */
    @Override
    public int insertBizRenewLoanInfo(BizRenewLoanInfo bizRenewLoanInfo)
    {
        bizRenewLoanInfo.setCreateTime(DateUtils.getNowDate());
        return bizRenewLoanInfoMapper.insertBizRenewLoanInfo(bizRenewLoanInfo);
    }

    /**
     * 修改续贷信息
     * 
     * @param bizRenewLoanInfo 续贷信息
     * @return 结果
     */
    @Override
    public int updateBizRenewLoanInfo(BizRenewLoanInfo bizRenewLoanInfo)
    {
        bizRenewLoanInfo.setUpdateTime(DateUtils.getNowDate());
        return bizRenewLoanInfoMapper.updateBizRenewLoanInfo(bizRenewLoanInfo);
    }

    /**
     * 批量删除续贷信息
     * 
     * @param renewLoanIds 需要删除的续贷信息ID
     * @return 结果
     */
    @Override
    public int deleteBizRenewLoanInfoByIds(String[] renewLoanIds)
    {
        return bizRenewLoanInfoMapper.deleteBizRenewLoanInfoByIds(renewLoanIds);
    }

    /**
     * 删除续贷信息信息
     * 
     * @param renewLoanId 续贷信息ID
     * @return 结果
     */
    @Override
    public int deleteBizRenewLoanInfoById(String renewLoanId)
    {
        return bizRenewLoanInfoMapper.deleteBizRenewLoanInfoById(renewLoanId);
    }


    public List<BizRenewLoanInfo> buildBizRenewLoanInfos(List<BizRenewLoanInfo> bizRenewLoanInfos) {
        bizRenewLoanInfos.stream().
                forEach(bizRenewLoanInfo -> {
                    String pciBelongNo = bizRenewLoanInfo.getPciBelongNo();
                    if (StringUtils.isNotBlank(pciBelongNo)) {
                        String biz_industry_type = DictUtils.getDictLabel("biz_industry_type", pciBelongNo);
                        if (StringUtils.isNotBlank(biz_industry_type)) {
                            bizRenewLoanInfo.setPciBelongType(biz_industry_type);
                        }
                    }
                    String customerAreaNo = bizRenewLoanInfo.getCustomerAreaNo();
                    if (StringUtils.isNotBlank(customerAreaNo)) {
                        String area_codes = DictUtils.getDictLabel("area_codes", customerAreaNo);
                        if (StringUtils.isNotBlank(area_codes)) {
                            bizRenewLoanInfo.setCustomerArea(area_codes);

                        }
                    }
                });
        return bizRenewLoanInfos;
    }
}
